package cn.xuewenbao.ucenter.mapper;

import cn.xuewenbao.ucenter.entity.Member;
import cn.xuewenbao.ucenter.entity.vo.MemberProfileVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author mafayu
 * @since 2021-03-29
 */
@Mapper
public interface MemberMapper extends BaseMapper<Member> {

    @Select("SELECT m.id, m.username, m.avatar, m.description, (SELECT COUNT(1) FROM follow f WHERE f.user_id = #{userId} AND f.followed_user_id = m.id)>0 AS isFollow \n" +
            ", (SELECT COUNT(1) FROM black_list b WHERE b.user_id = #{userId} AND b.black_id = m.id)>0 AS isBlack " +
            "FROM member m\n" +
            "WHERE m.id = #{memberId}")
    MemberProfileVo selectMemberProfileByMemberIdAndUserId(String memberId, String userId);
}
